﻿using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Sustainalytics.Entities.ESGRatings;

namespace Sustainalytics.CRT.Synchronization
{
    public static class FocusedRatingsPercentileManager
    {

        public static Task<float> GetPercentile(double companyScore, IEnumerable<EsgFocusPercentileThreshold> thresholds)
        {
            var theshold = thresholds.FirstOrDefault(t => t.LowerBound <= companyScore && companyScore < t.UpperBound);

            return Task.FromResult(theshold?.Value * 100 ?? float.NaN);
        }

    }
}